<?php

class Note extends Controller{

    function Note()
    {
        parent::Controller();
        $this->load->helper(array('form','url'));
    }
    
    function mine()
    {
        $uid = $this->session->userdata('userid');
        $data['title'] = 'My Notes';
        $data['heading'] = 'My Notes';
        $data['query'] = $this->db->get_where('note',array('author'=>$uid));
        $this->load->view('mine',$data);
    }

    function add()
    {
        $this->load->view('note_add');
    }

    function addnote()
    {
        if($this->input->post('author')&&$this->input->post('title')&&$this->input->post('address')&&$this->input->post('content'))
        {
            $this->load->model('Notes','',True);
            $this->Notes->add();
            redirect('note/mine','refresh');
        }else
        {
            redirect('home/index','refresh');
        }
    }

    function edit()
    {
        $nowuid = $this->session->userdata('userid');
        $nid = $this->uri->segment(3);
        $query = $this->db->get_where('note',array('id'=> $nid));

        if($query->num_rows()>0&&$query->result->author = 20)//判断是否取到值且对应相应的UID
        {
            $data['title'] = 'Edit Note';
            $data['heading'] = 'Edit Note';
            $data['result'] = $query->row_array();
            $this ->load->view('note_edit',$data);
        }else{
        redirect('/note/mine','refresh');
        }
    }

    function editnote()
    {
        if($this->input->post('author')&&$this->input->post('title')&&$this->input->post('address')&&$this->input->post('content'))
        {
            $this->load->model('Notes','',True);
            $this->Notes->edit();
            redirect('note/mine','refresh');
        }else
        {
            redirect('home/index','refresh');
        }
    }

    function delete()
    {
        $this->db->delete('note',array('id' => $this->uri->segment(3)));
        redirect('/note/mine','refresh');
    }

    function ListNoteByProcess($proid)
    {
        $query = $this->db->get_where('note',array('process'=>$proid));
        if($query->num_rows()>0)
        {
            foreach($query->result() as $row)
            {
                print_r($row);
            }
        }
    }

}
